# class Test:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def abc(self):
#         print('内部：', self.name)
#
#
# t = Test('张三', 10)
#
# t.abc()
#
# print('外部：', t.name)


import requests

# 登录成功
resp = requests.post(url='http://ihrm-test.itheima.net/api/sys/login',
                     headers={"Content-Type": "application/json"},
                     json={"mobile": "13800000002", "password": "123456"})

print('登录成功：', resp.json())

# 获取、拼接令牌
token = "Bearer " + resp.json().get('data')  # 写入全局变量
print(token)

# 添加员工
resp = requests.post(url='http://ihrm-test.itheima.net/api/sys/user',
              headers={"Content-Type": "application/json", "Authorization": token},
              json={"username": "爱因斯坦",
                    "mobile": "17289436788",
                    "timeOfEntry": "2021-07-12",
                    "formOfEmployment": 1,
                    "departmentName": "测试0607",
                    "departmentId": "1412421425733664768",
                    "workNumber": "234",
                    "correctionTime": "2021-07-30T16:00:00.000Z"})
print('添加员工：', resp.json())

# 获取添加员工成功的id
emp_id = resp.json().get('data').get('id')
# print('员工id=', emp_id)

# 查询员工  ---/api/sys/user/:target 直接将 “:target” 替换为 emp_id 变量值即可。
resp = requests.get(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                    headers={"Content-Type": "application/json", "Authorization": token})
print('查询员工：', resp.json())

# 修改员工
resp = requests.put(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                    headers={"Content-Type": "application/json", "Authorization": token},
                    json={"username":"小猪佩奇"})
print('修改员工：', resp.json())

# 删除员工
resp = requests.delete(url='http://ihrm-test.itheima.net/api/sys/user/' + emp_id,
                    headers={"Content-Type": "application/json", "Authorization": token})
print('删除员工：', resp.json())

# 查询员工列表
resp = requests.get(url='http://ihrm-test.itheima.net/api/sys/user?page=1&size=10',
                    headers={"Content-Type": "application/json", "Authorization": token})
print('查询员工列表：', resp.json())

